//
//  EquipmentCell.m
//  QoilPublic
//
//  Created by SunChao on 2018/4/13.
//  Copyright © 2018年 孙超. All rights reserved.
//

#import "EquipmentCell.h"
#import "QPerfectOrderInforMationVC.h"
#import "EqumentDetailVC.h"
#import "MJExtension.h"
#import "QSendingMapVC.h"
#import "MovingAnnotationViewController.h"
#import "CoordinatesModel.h"
#import "UIButton+ChaoGe.h"
@implementation EquipmentCell
- (void)setFrame:(CGRect)frame
{
    //修改cell的左右边距为10;
    //修改cell的Y值下移10;
    //修改cell的高度减少10;
    
    static CGFloat margin = 10;
//    frame.origin.x = margin;
//    frame.size.width -= 2 * frame.origin.x;
    frame.origin.y += margin;
    frame.size.height -= margin;
    
    [super setFrame:frame];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
   
   
}

- (void)setCellWithData:(NSDictionary *)dic{
    
    
   
    [self.historyBtn setImagePosition:ZXImagePositionLeft spacing:5.0f];
     [self.showDetailBtn setImagePosition:ZXImagePositionLeft spacing:5.0f];
     [self.callPhoneBtn setImagePosition:ZXImagePositionLeft spacing:5.0f];
    
    _deviceModel = [CoordinatesModel objectFromDict:dic];
    self.type = _deviceModel.ID;
    //工作状态
    if ([_deviceModel.workStatus isEqualToString:@"1"]) {
        
        self.workStatus.text = @"工作中";
        self.workStatus.textColor = [UIColor redColor];
        
    }else{
        
        self.workStatus.text = @"休息中";
        self.workStatus.textColor = [UIColor lightGrayColor];
    }
    //剩余油量
    self.remainOilPer.text = [NSString stringWithFormat:@"%@%@",_deviceModel.oilLevel,@"%"];
    //今日工时
    self.workTime.text = [NSString stringWithFormat:@"%@时",_deviceModel.dailyWorkTime];
    //地址
    self.address.text = [NSString stringWithFormat:@"%@",_deviceModel.formattedAddress];
//    self.address.text = [NSString stringWithFormat:@"%@,%@",deviceModel.lat,deviceModel.lng];
    self.deviceLabel.text = [NSString stringWithFormat:@"%@",_deviceModel.model];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.addOilBtn.layer.cornerRadius = 9.0f;
    self.addOilBtn.layer.masksToBounds = YES;
    
}
- (IBAction)OilBtnAction:(id)sender {
    
    
     UIViewController *currentVC = [QViewUtility getCurrentVC];
    QPerfectOrderInforMationVC *vc = [[QPerfectOrderInforMationVC alloc]init];
    [currentVC.navigationController pushViewController:vc animated:YES];
    
    
}
- (IBAction)ShowDetailBtn:(id)sender {
    
    NSLog(@"查看详情");
    UIViewController *currentVC = [QViewUtility getCurrentVC];
//
//    RecordViewController *recordVC = [[RecordViewController alloc]init];
//      [currentVC.navigationController pushViewController:recordVC animated:YES];
    UIStoryboard *mainSB = [UIStoryboard storyboardWithName:@"SCStoryboard" bundle:nil];
    EqumentDetailVC *selfdetailVC = [mainSB instantiateViewControllerWithIdentifier:@"EqumentDetailVC"];
    selfdetailVC.deviceId = self.type;
    [currentVC.navigationController pushViewController:selfdetailVC animated:YES];
}
- (IBAction)HistoryBtn:(id)sender {
    
    NSLog(@"历史轨迹");
    UIViewController *currentVC = [QViewUtility getCurrentVC];
    
    MovingAnnotationViewController *recordVC = [[MovingAnnotationViewController alloc]init];
    recordVC.ID = _type;
    [currentVC.navigationController pushViewController:recordVC animated:YES];
    
}
- (IBAction)CallPhoneBtn:(id)sender {
    
    [QViewUtility showPlayBoxView:PlayboxCallDriverPhone myBlock:^(NSInteger index) {
        if(index == 1){
            NSString *str = _deviceModel.operatorPhone;
            [QViewUtility callPhoneWithNumber:str];
        }
    }];
    
    
}

@end
